// 三角形最小路径和

import Foundation

func minimumTotal(_ triangle: [[Int]]) -> Int {
    let count = triangle.count
    
    if count <= 1 {
        return triangle.first?.first ?? 0
    }
    
    var dp = triangle
    
    print("dp",dp)
    
    for row in (0..<(count - 1)).reversed() {
        print("row: ",row)
        for col in (0..<triangle[row].count) {
            print("col: ",col)
            dp[row][col] += min(dp[row + 1][col], dp[row + 1][col + 1])
        }
        print(dp[row])
    }
    
    return dp[0][0]
}
